﻿using UnityEditor;
using UnityEngine;
using Util;

namespace UtilEditors
{
    public class FindWindow : BaseEditorWindow
    {

        Mlist<Transform> all = new Mlist<Transform>();
        private string Name;
        [MenuItem("Tools/辅助/Find辅助")]
        private static void Init()
        {
            Init<FindWindow>();
        }

        private void OnGUI()
        {
            Name = EditorGUILayout.TextField("组件名: ", Name);
            if (GUILayout.Button("Find", GUIs))
            {
                all.Clear();
                UtilEditor.AllScnenAllFind((tf) =>
                {
                    var com = tf.GetComponent(Name);
                    if (com)
                    {
                        all.Add(tf);
                    }
                    return false;
                });
            }
            for (int i = 0; i < all.Count; i++)
            {
                all[i] = EditorGUILayout.ObjectField(string.Format("{0}: {1}", i, all[i].transform.name), all[i], typeof(Transform), true) as Transform;
            }
        }
    }
}